import time

from selenium.webdriver.common.by import By
from common.Utils import BlogDirver

class BlogWrite:
    url = "http://8.137.19.140:9090/blog_edit.html"
    driver = BlogDirver.driver
    title = driver.title
    driver.get(url)

    def WriteTest(self):
        # 填写标题和内容
        self.driver.find_element(By.CSS_SELECTOR, "#title").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#title").send_keys("这是一篇博客")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        self.driver.back()

        # # 不填写标题，填写内容
        # self.driver.find_element(By.CSS_SELECTOR, "#title").clear()
        # self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        # alter = self.driver.switch_to.alert
        # time.sleep(2)
        # alter.accept()

        # # 填写标题，不填写内容
        # self.driver.find_element(By.CSS_SELECTOR, "#title").clear()
        # self.driver.find_element(By.CSS_SELECTOR,"#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#title").send_keys("这是一篇博客")
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # alter = self.driver.switch_to.alert
        # time.sleep(2)
        # alter.accept()
        #
        # # 不填写标题不填写内容
        # self.driver.find_element(By.CSS_SELECTOR, "#title").clear()
        # self.driver.find_element(By.CSS_SELECTOR,"#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # alter = self.driver.switch_to.alert
        # time.sleep(2)
        # alter.accept()

        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)").click()